<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>系统用户</title>
        <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
        <script type="text/javascript"  src="http://www.ijquery.cn/js/html5shiv.js"></script>
        <![endif]-->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/jquery-1.12.4.min.js">\x3C/script>')</script>
        <!--也可以用yepnopejs 加载器;直接是window对象-->
        <!--Font Awesome  一套绝佳的图标字体库和CSS框架 无需依赖JavaScript 无限缩放  完全免费 jquery-confirm里面用到 官网http://fontawesome.dashgame.com/-->
        <link href="css/font-awesome/css/font-awesome.min.css" rel="stylesheet">
        <!-- bootstrap 3.0.2 -->
        <link href="css/bootstrap-3.2.0/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <link href="css/bootstrap-box.css" rel="stylesheet" type="text/css" />
        <link href="css/bootstrap-page.css" rel="stylesheet" type="text/css" />
        <link href="js/resizableColumns/jquery.resizableColumns.css" rel="stylesheet" type="text/css" >
        <link href="css/myStyle.css" rel="stylesheet" type="text/css" />
        <link href="js/jquery-confirm/jquery-confirm.css" rel="stylesheet" type="text/css" />
        <link href="js/jquery-confirm/jquery-confirm.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/jquery-confirm/jquery-confirm.js"></script>
        <script type="text/javascript" src="js/resizableColumns/jquery.resizableColumns.js"></script>
        <script type="text/javascript" src="js/jsviews.js"></script>
        <script src="js/base.js" type="text/javascript"></script>
        <script type="text/javascript" src="js/loadTmpl.js"></script>
        <script type="text/javascript" src="js/tableGrid/jquery.tableGrid.js"></script>
        <script type="text/javascript" src="js/layer/layer.js"></script>
        <script type="text/javascript">
        $.views.converters("isSelected",function(first,last){
        	if(first==null) return "";
			return first.parentId==last? "selected=selected":"";
		});
        	//从后台取数据，并加载模板
	        function displayContent(){
	        	var userName = $("#userName").val();
				var nextPage=$("#_click_page").val();			//不变
				if(typeof(nextPage) == 'undefined' || nextPage==""){
					nextPage=0;
				}
				var pagesize=$("#selectPageSize").val();
				if(typeof(pagesize) == 'undefined' || pagesize==""){
					pagesize=10;
				}
				var sortData="[{property:'userId',direction:'ASC'}]";
				var jsonFilter="{search_LIKE_userName:\""+userName+"\"}";
				var url=root+"xaCmsUser/showCmsUser";
				$.ajax({
					url:url,
					dataType:'json',
					data:{
						pageSize:pagesize,
						nextPage:nextPage,
						sortData:"[{property:'userId',direction:'DESC'}]",
						jsonFilter:jsonFilter
					},
					success:function(data){
                        if ( typeof data === 'string' ) {
                            data = JSON.parse(data);
                        }
						console.log(data);
						var tableData=data.object.content;
		            	var tblContentHtml = $("#tableContentTmple").render(tableData);
		            	$("#mycontent").html(tblContentHtml);
		            	//去掉复选状态
						$("#_selectAll").prop({checked:false});
		            	//加载分页器
		            	loadTmpl.renderExternalTemplate("page", "#displayPage", data.object);
					}
				});
	        }
	         //从后台取数据，并加载模板
	        function displayContent1(search){
		        if(search==1){
					nextPage=0;
				}
	        	var userName = $("#userName").val();
				//var nextPage=$("#_click_page").val();			//不变
				if(typeof(nextPage) == 'undefined' || nextPage==""){
					nextPage=0;
				}
				var pageSize=$("#selectPageSize").val();
				if(typeof(pageSize) == 'undefined' || pageSize==""){
					pageSize=10;
				}
				var sortData="[{property:'userId',direction:'ASC'}]";
				var jsonFilter="{search_LIKE_userName:\""+userName+"\"}";
				var url=root+"xaCmsUser/showCmsUser";
				$.ajax({
					url:url,
					dataType:'json',
					data:{
						nextPage:nextPage,
						pageSize:pageSize,
                        sortData:"[{property:'userId',direction:'DESC'}]",
						jsonFilter:jsonFilter
					},
					success:function(data){
                        if ( typeof data === 'string' ) {
                            data = JSON.parse(data);
                        }
						var tableData=data.object.content;
						var tblContentHtml = $("#tableContentTmple").render(tableData);
		            	$("#mycontent").html(tblContentHtml);
		            	//去掉复选状态
						$("#_selectAll").prop({checked:false});
		            	//加载分页器
		            	loadTmpl.renderExternalTemplate("page", "#displayPage", data.object);
					}
				});
	        }
			$(function(){
				$("#example2").resizableColumns({});	//列拖动
				//行高亮,选中
				$("#example2").tableGrid({
					checkAllId:"_selectAll",	//全选框的ID属性
					singleCheckboxClass:"ckSelect",
					selectRowClass:"warning",
					paging:"displayPage",
					pageAjax:function(){
						displayContent();
					}
				});
				//点击新增按钮
				$("#addSome").click(function(){
					window.location.href=root+"userEdit.html?userId=0";
				});
				//点击修改按钮
				$("#updateSome").click(function(){
					var updateArray=new Array();
					$(".ckSelect").each(function(){
                    	var check=$(this).is(':checked');
                    	if(check){
							var _id =$(this).attr("ckId");
							updateArray.push(_id);
                        }
                    });
					if(updateArray.length==0){
						myAlert("请选择要编辑的项");
						return;
					}
					if(updateArray.length>1){
						myAlert("每次只能编辑一项");
						return;
					}
					window.location.href=root+"userEdit.html?userId="+updateArray[0];
				});
				//点击查询按钮
				$("#search").click(function(){
					displayContent1(1);
				});
				//点击删除按钮
				$("#delSome").click(function(){
					var delStr="";
					var delArray=new Array();
					$(".ckSelect").each(function(){
                    	var check=$(this).is(':checked');
                    	if(check){
							var _id =$(this).attr("ckId");
							delStr+=parseInt(_id)+",";
							delArray.push(_id);
                        }
                    });
                    if(delStr.length==0){
                        myAlert("请选择要删除的项");
						return
                    }
                    if($.inArray('1',delArray) != -1){
                    	myAlert("superadmin是超级管理员，不能删除");
                    	return;
                    }
                    myConfirm("你确定要删除选中项吗？", function () {
                        var delIds=""+delArray+"";
                        var url=root+"xaCmsUser/user/"+delIds;
                        $.ajax({
                            url:url,
                            type:'DELETE',
                            dataType:'json',
                            success:function(data){
                                if ( typeof data === 'string' ) {
                                    data = JSON.parse(data);
                                }
                                if(data.status==1){
                                    displayContent();
                                }else{
                                    myAlert(data.result);
                                }
                            }
                        });
                    });
				});
				//点击重置密码按钮
				$("#resetPass").click(function(){
					var updateArray=new Array();
					$(".ckSelect").each(function(){
                    	var check=$(this).is(':checked');
                    	if(check){
							var _id =$(this).attr("ckId");
							updateArray.push(_id);
                        }
                    });
					if(updateArray.length==0){
						myAlert("请选择要重置的用户");
						return;
					}
					if(updateArray.length>1){
						myAlert("每次只能重置一个用户的密码");
						return;
					}
					myConfirm("你确定要重置该用户的密码吗？", function () {
                        $.ajax({
                            url:root+'xaCmsUser/reset/'+updateArray[0],
                            type:'put',
                            dataType:'json',
                            success:function(data){
                                myAlert(data.result);
                            }
                        });
                    });

				});
			});
        </script>
    </head>
    <body>
      <section>
          <div>
              <div class="col-xs-12">
                  <div class="box">
                      <div class="box-header">
                       <span class="add-on" style="float:left;line-height:30px;">用户名：</span><input type="text" class="form-control input-sm" placeHolder="用户名" style="width:200px;float:left;margin-right:20px;" id="userName"/>
                          <input type="button" value="搜索" id="search" class="searchBtn">
                      </div>
                      <div class="box-header">
                          <input type="button" value="新增" id="addSome" class="btn btn-success">
                          <input type="button" value="删除" id="delSome" class="btn btn-danger">
                          <input type="button" value="编辑" id="updateSome" class="btn btn-info">
                          <input type="button" value="重置密码" id="resetPass" class="btn btn-danger">
                      </div>
                      <div class="box-body table-responsive">
                          <table id="example2" class="table table-bordered table-hover">
                              <thead>
                                  <tr>
                                      <th><input type="checkbox" id="_selectAll" /></th>
                                      <th id='userName'>用户名</th>
                                      <th id='realName'>真实姓名</th>
                                      <th id='mobile'>手机号</th>
                                      <th id='email'>email</th>
                                  </tr>
                              </thead>
                              <!-- 表格内容 start -->
                              <tbody id="mycontent"></tbody>
                              <!-- 表格内容 end -->
                          </table>
                          <!-- 分页标签 start -->
                          <div class="row page_big_div" id="displayPage"></div>
                          <!-- 分页标签 end -->
                          <script id="tableContentTmple" type="text/x-jsrender">
								<tr><td><input id="ck_{{:userId}}" ckId="{{:userId}}" class="ckSelect" type="checkbox" /></td><td>{{:userName}}</td><td>{{:realName}}</td><td>{{:mobile}}</td><td>{{:email}}</td></tr>
						  </script>
                  </div>
              </div>
          </div>
      </section>
<!-- 新增对话框  start -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
</div>

<script type="text/x-jsrender" id="newOrupdateTmpl">
	<div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">
{{if selectedId}}
               修改资源信息
{{else}}
               新增资源信息
{{/if}}
            </h4>
         </div>
         <div class="modal-body">
            <fieldset> 
				<div class="control-group">
					<label for="userPhoto2" class="control-label">资源名称</label>
					<div class="controls">
						{{if selectedId}}
							<input type="text" placeholder="请填写资源名称" id="resourceName1" name="resourceName" value="{{:selectedId.resourceName}}" />
							<input type="hidden" id="resourceId1" value="{{:selectedId.resourceId}}" />
						{{else}}
							<input type="text" placeholder="请填写资源名称" id="resourceName1" name="resourceName" />
							<input type="hidden" id="resourceId1" />
						{{/if}}
					</div>
				</div>
				<!-- Select Basic -->
				<div class="control-group">
					<label for="userType" class="control-label">父资源</label>
					<div class="controls" id="parentResourceContainer">
						<select id="parentId1" name="parentId">
							<option value="">选择父资源</option>
							{{for optionItem}}
								<option value="{{:resourceId}}" {{isSelected:#parent.parent.data.selectedId resourceId}}>{{:resourceName}}</option>
							{{/for}}
						</select>
					</div>
				</div>
				<div class="control-group">
					<label for="userPassword" class="control-label">资源路径</label>
					<div class="controls">
					{{if selectedId}}
						<input type="text" required="required" id="resourceUrl1"  placeholder="请输入资源相对路径" name="resourceUrl" value="{{:selectedId.resourceUrl}}"/>
					{{else}}
						<input type="text" required="required" id="resourceUrl1"  placeholder="请输入资源相对路径" name="resourceUrl"/>
					{{/if}}
					</div>
				</div>
			</fieldset>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" id="saveOrupdate" class="btn btn-primary">
               确定
            </button>
         </div>
      </div>
</script>


<!-- 新增对话框  end -->
    </body>
</html>